package com.ruoyi.plan.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.plan.domain.SysPlan;
import com.ruoyi.plan.service.ISysPlanService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 计划信息Controller
 * 
 * @author ruoyi
 * @date 2023-11-12
 */
@RestController
@RequestMapping("/plan")
public class SysPlanController extends BaseController
{
    @Autowired
    private ISysPlanService sysPlanService;

    /**
     * 查询计划信息列表
     */
    @RequiresPermissions("plan:plan:list")
    @GetMapping("/list")
    public TableDataInfo list(SysPlan sysPlan)
    {
        startPage();
        List<SysPlan> list = sysPlanService.selectSysPlanList(sysPlan);
        return getDataTable(list);
    }

    /**
     * 导出计划信息列表
     */
    @RequiresPermissions("plan:plan:export")
    @Log(title = "计划信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPlan sysPlan)
    {
        List<SysPlan> list = sysPlanService.selectSysPlanList(sysPlan);
        ExcelUtil<SysPlan> util = new ExcelUtil<SysPlan>(SysPlan.class);
        util.exportExcel(response, list, "计划信息数据");
    }

    /**
     * 获取计划信息详细信息
     */
    @RequiresPermissions("plan:plan:query")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId)
    {
        return success(sysPlanService.selectSysPlanByPlanId(planId));
    }

    /**
     * 新增计划信息
     */
    @RequiresPermissions("plan:plan:add")
    @Log(title = "计划信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPlan sysPlan)
    {
        return toAjax(sysPlanService.insertSysPlan(sysPlan));
    }

    /**
     * 修改计划信息
     */
    @RequiresPermissions("plan:plan:edit")
    @Log(title = "计划信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPlan sysPlan)
    {
        return toAjax(sysPlanService.updateSysPlan(sysPlan));
    }

    /**
     * 删除计划信息
     */
    @RequiresPermissions("plan:plan:remove")
    @Log(title = "计划信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds)
    {
        return toAjax(sysPlanService.deleteSysPlanByPlanIds(planIds));
    }
}
